const { mongo } = require('mongoose')
const mongoose = require('./db')
mongoose.set('strictQuery', true);

const Schema = mongoose.Schema

// 存证类型
let existingEviTypeSchema = new Schema({
  name: String,
})
let existingEviTypeModel = mongoose.model('existingEviType', existingEviTypeSchema, 'existingEviType')
// 存证文件类型
let fileTypesSchema = mongoose.Schema({
  name: String,
})
let fileTypesModel = mongoose.model('fileTypes', fileTypesSchema, 'fileTypes')
// 存证
let existingEvidenceSchema = new Schema({
  name: String,
  createTime: {
    type: Date,
    default: new Date()
  },
  type: {
    type: mongoose.Types.ObjectId,
    ref: "existingEviType",
  },    // 存证类型
  stats: Number,
  fileName: String,
  fileSize: Number,
  fileType: {
    type: mongoose.Types.ObjectId,
    ref: "fileTypes",
  }, //文件类型
  height: Number,
  fileHash: String,//文件哈希
  eeHash: String,//存证哈希也是头哈希
  fatherHash: String,//父哈希
  is3D: {
    type: Boolean,
    default: false
  }
})
let existingEvidenceModel = mongoose.model('existingEvidence', existingEvidenceSchema, 'existingEvidence')
// 取证类型
let ovTypeSchema = new Schema({
  name: String
})
let ovTypeModel = mongoose.model('ovType', ovTypeSchema, 'ovType')

// 取证
let obtainEvidenceSchema = new Schema({
  // user:{} //购买者
  name: String,
  type: {
    type: mongoose.Types.ObjectId,
    ref: "ovType",
  },    // 取证类型
  fileName: String,
  stats: {
    type: Number,
    default: 1
  },
  height: Number,
  fileHash: String,//文件哈希
  eeHash: String,//取证哈希也是头哈希
  fatherHash: String,//父哈希
  createTime: {
    type: Date,
    default: new Date()
  },
  is3D: {
    type: Boolean,
    default: false
  }
})
let obtainEvidenceModel = mongoose.model('obtainEvidence', obtainEvidenceSchema, 'obtainEvidence')
// 套餐
let packageSChema = new Schema({
  name: String,
  num: Number,
  type: {
    type: mongoose.Types.ObjectId,
    ref: "existingEviType",
  },    // 存证类型
  discount: Number,//折扣
  price: Number,
  sort: Number,
  stats: Boolean,
})
let packageModel = mongoose.model('package', packageSChema, 'package')

// 订单
let orderSchema = new Schema({
  user: {
    type: mongoose.Types.ObjectId,
    ref: "login",
  }, //购买者
  type: {
    type: mongoose.Types.ObjectId,
    ref: "package",
  },    // 套餐类型
  num: Number,
  price: Number,
  stats: {
    type: Boolean,
    default: false
  },
  paymentType: Boolean,
  createTime: {
    type: Date,
    default: new Date()
  },
})
let orderModel = mongoose.model('order', orderSchema, 'order')
module.exports = { orderModel, existingEvidenceModel, existingEviTypeModel, fileTypesModel, packageModel, ovTypeModel, obtainEvidenceModel }